//
//  AppCommunicationManager.h
//  BanBu
//
//  Created by 来国 郑 on 12-7-26.
//  Copyright (c) 2012年 17xy. All rights reserved.
//

#import <Foundation/Foundation.h>
#import "ASIHttprequest.h"
#import "ASIFormDataRequest.h"
#import "ASIProgressDelegate.h"
#import "ASINetworkQueue.h"
#import "BanBuAPIs.h"
#import "AsyncSocket.h"
#import "BanBuRequestDelegate.h"
#import "NSData+Base64.h"
#import "MKNetworkKit.h"
#import "RecordAudio.h"
#import "BanBu_SmileViewAPI.h"

@class AppDataManager;



#define AppComManager [AppCommunicationManager sharedAppCommunicationManager]

#define SepTimeInterval 3

#define MaxRetryTimes 5
typedef enum
{
    CacheTypeChatImage = 0,
    
    CacheTypeChatAudio
    
} CacheType;

typedef enum
{
  NetReachableNone,
  
  NetReachableWifi,
    
  NetReachable3G
}NetStatus;




@protocol BanBuRequestDelegate;

@interface AppCommunicationManager : NSObject<ASIProgressDelegate>{
    BOOL isReach;
    
    
    MKNetworkOperation *_byUserOP;

    MKNetworkOperation *_byAllOP;
}

@property(nonatomic, retain)Reachability *hostReach;
@property(nonatomic, retain)ASINetworkQueue *networkQueue;
@property(nonatomic, retain)ASINetworkQueue *uploadQueue;
@property(nonatomic, retain)ASINetworkQueue *receiveMsgQueue;
@property(nonatomic, retain)AsyncSocket *chatSocket;
@property(nonatomic, assign)NSTimer *receiveMsgTimer;
@property(nonatomic, retain)NSMutableDictionary *receiveInfo;
@property(nonatomic,assign)NetStatus netStatus;
// 这是接受绣球的timer
//修改：yinlinlin,添加相册文件上传队列
@property(nonatomic, retain) ASINetworkQueue * updateAlbumdataQueue;
//修改完成：yinlinlin
@property(nonatomic,assign)NSTimer *receiveSingleMsgTimer;

// 这是回调
@property(nonatomic,retain)NSMutableData *receivedata;
@property(nonatomic,assign)id<BanBuRequestDelegate>delegate;

- (void)creatChatConnect;
- (void)DisconnectChat;

+ (AppCommunicationManager *)sharedAppCommunicationManager;
- (void)cancalHandlesForObject:(id)adelegate;
- (void)cancalHandleNemed:(NSString *)name forObject:(id)adelegate;
- (BOOL)respondsDic:(NSDictionary *)dataDic isFunctionData:(NSString *)fc;
- (NSString *)getPar:(NSString *)parStr;

- (NSDictionary *)getAMsgFrom64String:(NSString *)encodedString;

#pragma mark - 获取缓存文件的路径
//下载音频文件路径
-(NSString *)pathForFolder:(NSString *)folderName;

//表情的路径
-(NSString *)pathForEmo:(NSString *)emoName withFolder:(NSString *)folderName;

//普通缓存文件的路径
- (NSString *)pathForMedia:(NSString *)mediaName;

//对话消息的路径
- (NSString *)pathForMsgMedia:(NSString *)mediaName;

//视频消息的路径
- (NSString *)pathForVideoMsgMedia:(NSString *)mediaName;

//获取消息路径
- (NSString *)pathForMsgMedia:(NSString *)mediaName cacheFolder:(NSString *)folderName;

//视频相册的路径
- (NSString *)pathForVideoAlbumMedia:(NSString *)mediaName;

//收藏的表情
- (NSString *)pathForCollect:(NSString *)emoPath;

//收藏的图片
- (NSString *)pathForCollectImage:(NSString *)imagePath;

//魔法文字的图片路径
- (NSString *)pathForMagicWordsImage:(NSString *)imagePath;

#pragma mark - 客户端与服务器的交互

//获取数据
//获取视频的缩略图
- (void)getBanBuMediaThumbnail:(NSString *)mediaUrlStr forMsgID:(NSString *)msgid fromUid:(NSString *)uid delegate:(id)adelegate;
//获取魔法表情的缩略图
- (void)getBanBuMediaMagicThumbnail:(NSString *)mediaUrlStr forMsgID:(NSString *)msgid fromUid:(NSString *)uid delegate:(id)adelegate;
//获取服务器上对话部分多媒体信息：魔法表情等
- (void)getBanBuMagicGifMedia:(NSString *)mediaUrlStr forMsgID:(NSString *)msgid fromUid:(NSString *)uid delegate:(id)adelegate;

- (void)getBanBuData:(NSString *)query par:(NSDictionary *)parDic delegate:(id)adelegate;
- (void)getBanBuMedia:(NSString *)mediaUrlStr forMsgID:(NSString *)msgid fromUid:(NSString *)uid delegate:(id)adelegate;
- (void)getBanBuMedia:(NSString *)mediaUrlStr delegate:(id)adelegate;
- (void)getBanBuData:(NSString *)query par:(NSDictionary *)parDic delegate:(id)adelegate Unlogin:(BOOL)flag;

//获取翻译数据
-(void)getTranslateUrl:(NSString *)urlString delegate:(id)adelegate;

#pragma mark - 提交收藏的表情、图片、文字、语音;获取魔法文字的html
//提交服务器收藏的表情
- (void)getBanBuDataWIthCollectEmo:(NSString *)query par:(NSDictionary *)parDic delegate:(id)adelegate;

//提交服务器收藏的表情
- (void)uploadCollectManuscript:(NSString *)query par:(NSDictionary *)parDic delegate:(id)adelegate;

//获取魔法文字的html
-(void)getMagicWordsHtml:(NSString *)query par:(NSDictionary *)parDic delegate:(id)adelegate;

//获取服务器上魔法文字的素材图片
- (void)getMagicWordsImage:(NSString *)mediaUrlStr  withFolder:(NSString *)folderName delegate:(id)adelegate withImageView:(UIImageView *)imageView;
#pragma mark - 
//上传文件
- (void)uploadVerifyData:(NSData *)videoData image:(NSData *)imageData delegate:(id)delegate;//上传视频认证的头像和视频
- (void)uploadRegAvatarImage:(NSData *)imageData Par:(NSDictionary *)parDic delegate:(id)adelegate;
- (void)uploadBanBuMedia:(NSData *)mediaData mediaName:(NSString *)mediaName par:(NSDictionary *)parDic delegate:(id)adelegate;
- (void)uploadBanBuMediaThumbnail:(NSData *)mediaData mediaName:(NSString *)mediaName par:(NSDictionary *)parDic delegate:(id)adelegate;

- (void)uploadBanBuBroadcastMedia:(NSData *)mediaData mediaName:(NSString *)mediaName par:(NSDictionary *)parDic delegate:(id)adelegate;
- (void)uploadSeveralImages:(NSArray *)imageArr delegate:(id)delegate;
//修改相册图片马赛克
- (void)modifyAlbumPicture:(NSData *)sendData par:(NSDictionary *)parDic delegate:(id)delegate;

//上传收藏的表情
- (void)uploadCollectedEmo:(NSData *)mediaData mediaName:(NSString *)mediaName par:(NSDictionary *)parDic delegate:(id)adelegate;
-(NSString *)remove_:(NSString *)string;

#pragma mark - 长连接 接收消息
//addBy：王小军 at:2013-7-11 17:21:00
@property (copy , nonatomic) NSString * lastflag;           //长连接校验字段
@property (assign, nonatomic) BOOL isReceivingDialods;      //是否正在接受对话消息
@property (retain, nonatomic) NSMutableData * mutableData;  //接收到的消息的数据

- (void)startReceiveMsgFromUid:(NSString *)uid forDelegate:(id)delegate;
- (void)stopReceiveMsgForUid:(NSString *)uid;
- (void)receiveMsgFromUser:(NSString *)userid delegate:(id)delegate;
//接收消息
-(void)receiveDataQuery:(NSString *)query andRequestUrlStr:(NSString *)requestUrlStr  delegate:(id)delegate;

#pragma mark - 下载主题、彩蛋、收藏的图片、语音、表情等
- (void)getEmoImage:(NSString *)mediaUrlStr withImageName:(NSString *)imageName withFolder:(NSString *)folderName delegate:(id)adelegate withImageView:(UIImageView *)imageView;
//下载主题
-(void)downLoadFileWithUrl:(NSString *)url withsaveName:(NSString *)fileName delegate:(id)delegate;

//下载彩蛋图片、语音
-(void)downLoadEggsWithUrl:(NSString *)url withSaveName:(NSString *)fileName delegate:(id)delegate;

//下载收藏的图片、语音文件
-(void)downloadAmsgFileWithUrl:(NSString *)fileUrl withUserId:(NSString *)userid withFolder:(NSString *)folderName withDelegate:(id)delegate;
//下载表情包
-(void)downLoadEmoWithUrl:(NSString *)url withEmoInfoDic:(NSDictionary *)emoInfoDic delegate:(id)delegate;
#pragma mark - 其他方法

-(NSString *)creatGifDataURL:(NSString *)query par:(NSDictionary *)parDic;
//获取用户地理位置信息
- (void)getBanBuPosition:(CLLocation *)_loc delegate:(id)adelegate;

//修改：yinlinlin：上传照片的方法
-(UIImage *)reSizeImage:(UIImage *)image toSize:(CGSize)reSize;

-(void)updatePhotosToAlbum:(NSDictionary*)photoDict delegate:(id)adelegate;
//修改：yinlinlin:添加单独获取相册列表的方法2014/06/16
- (void)getBanBuAlbumData:(NSString *)query par:(NSDictionary *)parDic delegate:(id)adelegate;


@end
